/**
 * @Description: 全局自动注册组件，前缀加上 g-
 * @Author BPF
 * @create 2021/8/20 21:49
 */
import { requireAllModule, kebabCase } from '@bianpengfei/utils'
// import setting from '/src/setting'

export default {
  install: (app) => {
    const prefix = 'g-'
    requireAllModule({
      requireContext: require.context('@/components/base/', true, /\.vue$/),
      exclude: []
    })
      .concat(
        requireAllModule({
          requireContext: require.context('@/components/business', true, /\.vue$/),
          exclude: []
        })
      )
      .forEach(([v]) => {
        const _default = v?.default
        if (_default?.name) {
          let defaultName = kebabCase(_default.name)
          const name = defaultName.startsWith(prefix) ? defaultName : `${prefix}${defaultName}`
          app.component(name, _default)
        }
      })
  }
}
